<template>
  <div>
    <el-table
    :data="tableData"
    :stripe="true"
    style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="小组">
              <span>{{ props.row.group_id }}</span>
            </el-form-item>
            <el-form-item label="文件类别">
              <span>{{ category[props.row.type-1].value }}</span>
            </el-form-item>
            <el-form-item label="文件编号">
              <span>{{ props.row.file_id }}</span>
            </el-form-item>
            <el-form-item label="文件名">
              <span>{{ props.row.name }}</span>
            </el-form-item>
            <el-form-item label="提交日期">
              <span>{{ props.row.sub_date}}</span>
            </el-form-item>
            <el-form-item label="提交时间">
              <span>{{ props.row.sub_time }}</span>
            </el-form-item>
            
            <el-form-item label="批改老师">
              <span>{{ props.row.teacher_name === null?'未批改': props.row.teacher_name}}</span>
            </el-form-item>
            <el-form-item label="批改日期">
              <span>{{ props.row.check_date === null?'未批改': props.row.check_date }}</span>
            </el-form-item>
            <el-form-item label="批改时间">
              <span>{{ props.row.check_time === null?'未批改':props.row.check_time }}</span>
            </el-form-item>
            <el-form-item label="评论">
              <span>{{ props.row.comments ===null?'未批改': props.row.comments }}</span>
            </el-form-item>
            <el-form-item label="状态">
              <span>{{ rate[props.row.status].value }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column
        label="小组"
        :filters=this.groups
        :filter-method="filterGroup"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <span>{{ scope.row. group_id}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="文件类别"
        :filters="[{ text:'项目需求说明书' ,value:1}, { text: '项目详细设计说明书', value: 2 },{ text: '项目概要设计说明书', value: 3 },{ text: '项目测试报告', value: 4 },{ text: '实验报告', value: 5 },{ text: '测试分析报告', value: 6 }]"
        :filter-method="filterCategory"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <span>{{ category[scope.row.type-1].value }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="文件编号">
        <template slot-scope="scope">
          <span>{{ scope.row.file_id }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="文件名">
        <template slot-scope="scope">
          <span >{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交日期"
       >
        <template slot-scope="scope">
          <span >{{ scope.row.sub_date}}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="提交时间">
        <template slot-scope="scope">
          <span >{{ scope.row.sub_time }}</span>
        </template>
      </el-table-column>
      

      
      <el-table-column
        label="状态"
        :filters=this.rateFillter
        :filter-method="filterRate"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <el-tag
          :type=tag[scope.row.status]
          disable-transitions>{{rate[scope.row.status].value}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column 
      label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleDownLoad(scope.$index, scope.row)">下载</el-button>
          <el-button
            size="mini"
            type="success"
            
            
            @click="handleCor(scope.$index, scope.row)">批改</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    
  </div>
  
</template>

<script>
import { showFile, downloadFile } from '@/api/user'




export default {
  
  data() {
    return {
      tableData: [],
      file_infor: {},
      rate: [],
      rateFillter:[],
      category:[],
      groups:[],
      tag:['info','success','success','warning','','danger'],
      wordUrl : '',
      baseUrl:'http://localhost:8080/'
    }
  },
  created: function() {
    showFile(this.$store.getters.token).then(response => {
      this.tableData = response.data.files
      this.rate = response.data.rate
      this.category=response.data.category
      var len=response.data.groups.length
      for(var i=0;i<len;i++ ){
        this.groups.push({text:'第'+response.data.groups[i].group_id+'组',value:response.data.groups[i].group_id})
      }
      len=this.rate.length
      for(var i=0;i<len;i++){
        this.rateFillter.push({text:this.rate[i].value,value:i})
      }
    })
  },
  methods: {

    handleDownLoad(index,row){
      this.wordUrl=this.baseUrl+this.tableData[index].name
      const link = document.createElement('a');
      link.href = this.wordUrl;
      link.setAttribute('download', this.tableData[index].name);
      link.click();
    },
    handleCor(index, row) {
      if(this.tableData[index].status===0){
        this.$store.commit('user/SET_FID',this.tableData[index].file_id)
        this.$router.push({
          path:'/file/correctFile'
        })
      }else{
        this.$message({
            message:"该文件已批改",
            type: "error"
        })
      }      
    },
    filterCategory(value,row){
      return row.type===value
    },
    filterGroup(value,row){
      return row.group_id===value
    },
    filterRate(value,row){
      return row.status===value
    }


    
  }

  
}

</script>


<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
